home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*----------------------------------------------------------------------------
- *
- * file : ui.c
- *
- * Author : Yusuf Attarwala
- * Date : Sep 93
- *
- *---------------------------------------------------------------------------*/
-
- #include "Xmincludes.h"
- #include "globals_vol.h"
- #include <Xm/Protocols.h>
- #include <X11/StringDefs.h>
-
- static Arg args[40];
- static int argcnt;
-
- static char *scrollCBs[] = {
- XmNincrementCallback,
- XmNdecrementCallback,
- XmNdragCallback,
- };
-
-
- static char *toggles[] = {"Draw Axes",
- "Degenerate",
- "Low Res",
- "DepthCue",
- "Do not blend",
- "Move Slice",
- "Display Clip Planes",
- };
-
- static char *buttons[] = {"Reset View",
- "Info/Help",
- "Exit"};
-
- static char *views[] = {"+x","+y","+z","-x","-y","-z"};
-
- extern void doExit();
- Widget clipButton[MAXCLIP];
-
- void
- createMenus(parent)
- Widget parent;
- {
-
- int i;
- Widget tb;
- void toggleCB(),clipOnOffCB(),clipMoveCB(),viewCB(),buttonCB();
- Widget form,toggleFrame,clipFrame1,clipFrame2,viewFrame,buttonFrame;
- Widget toggleRC,clipRC,clip2RC,viewRC,buttonRC;
-
- form = XtVaCreateManagedWidget("form",
- xmFormWidgetClass,parent,
- NULL);
-
- toggleFrame = XtVaCreateManagedWidget("ui",
- xmFrameWidgetClass, form,
- XmNleftAttachment, XmATTACH_FORM,
- XmNleftOffset, 1,
- XmNtopAttachment, XmATTACH_FORM,
- XmNtopOffset, 1,
- XmNrightAttachment, XmATTACH_FORM,
- XmNrightOffset, 1,
- NULL);
-
- clipFrame1 = XtVaCreateManagedWidget("ui",
- xmFrameWidgetClass, form,
- XmNleftAttachment, XmATTACH_FORM,
- XmNleftOffset, 1,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNtopWidget, toggleFrame,
- XmNrightAttachment, XmATTACH_FORM,
- XmNrightOffset, 1,
- NULL);
-
- clipFrame2 = XtVaCreateManagedWidget("ui",
- xmFrameWidgetClass, form,
- XmNleftAttachment, XmATTACH_FORM,
- XmNleftOffset, 1,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNtopWidget, clipFrame1,
- XmNrightAttachment, XmATTACH_FORM,
- XmNrightOffset, 1,
- NULL);
-
- viewFrame = XtVaCreateManagedWidget("ui",
- xmFrameWidgetClass, form,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNtopWidget, clipFrame2,
- XmNleftAttachment, XmATTACH_FORM,
- XmNleftOffset, 1,
- XmNrightAttachment, XmATTACH_FORM,
- XmNrightOffset, 1,
- NULL);
- buttonFrame = XtVaCreateManagedWidget("ui",
- xmFrameWidgetClass, form,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNtopWidget, viewFrame,
- XmNleftAttachment, XmATTACH_FORM,
- XmNleftOffset, 1,
- XmNrightAttachment, XmATTACH_FORM,
- XmNrightOffset, 1,
- XmNbottomAttachment, XmATTACH_FORM,
- NULL);
-
-
- toggleRC = XtVaCreateManagedWidget("toggleRC",
- xmRowColumnWidgetClass, toggleFrame,
- XmNpacking, XmPACK_TIGHT,
- XmNmarginWidth, 0,
- XmNmarginHeight, 0,
- NULL);
-
- for (i=0;i<XtNumber(toggles);i++) {
- tb = XtVaCreateManagedWidget(toggles[i],
- xmToggleButtonWidgetClass, toggleRC,
- XmNspacing, 2,
- NULL);
- XtAddCallback(tb,XmNarmCallback,toggleCB,i);
- }
-
- clipRC = XtVaCreateManagedWidget("ui",
- xmRowColumnWidgetClass, clipFrame1,
- XmNpacking, XmPACK_TIGHT,
- XmNmarginWidth, 0,
- XmNmarginHeight, 0,
- XmNorientation, XmHORIZONTAL,
- NULL);
-
- for (i=0;i<6;i++) {
- clipButton[i] = XtVaCreateManagedWidget(" ",
- xmToggleButtonWidgetClass, clipRC,
- XmNspacing, 2,
- NULL);
- XtAddCallback(clipButton[i],XmNarmCallback,clipOnOffCB,i);
- }
-
- /*
- clip2RC = XtVaCreateManagedWidget("ui",
- xmRowColumnWidgetClass, clipFrame2,
- XmNpacking, XmPACK_TIGHT,
- XmNmarginWidth, 0,
- XmNmarginHeight, 0,
- XmNorientation, XmHORIZONTAL,
- NULL);
-
- tb = XtVaCreateManagedWidget(" ",xmArrowButtonWidgetClass,clip2RC,
- XmNarrowDirection,XmARROW_LEFT,
- NULL);
- XtAddCallback(tb,XmNactivateCallback,clipMoveCB,-1);
-
- tb = XtVaCreateManagedWidget(" ",xmArrowButtonWidgetClass,clip2RC,
- XmNarrowDirection,XmARROW_RIGHT,
- NULL);
- XtAddCallback(tb,XmNactivateCallback,clipMoveCB,1);
- */
-
- viewRC = XtVaCreateManagedWidget("viewRC",
- xmRowColumnWidgetClass, viewFrame,
- XmNpacking, XmPACK_TIGHT,
- XmNmarginWidth, 0,
- XmNmarginHeight, 0,
- XmNorientation, XmHORIZONTAL,
- NULL);
-
- for (i=0;i<XtNumber(views);i++) {
- tb = XtVaCreateManagedWidget(views[i],
- xmPushButtonWidgetClass, viewRC,
- XmNspacing, 2,
- NULL);
- XtAddCallback(tb,XmNactivateCallback,viewCB,i);
- }
-
- buttonRC = XtVaCreateManagedWidget("buttonRC",
- xmRowColumnWidgetClass, buttonFrame,
- XmNpacking, XmPACK_TIGHT,
- XmNmarginWidth, 0,
- XmNmarginHeight, 0,
- NULL);
-
- for (i=0;i<XtNumber(buttons);i++) {
- tb = XtVaCreateManagedWidget(buttons[i],
- xmPushButtonWidgetClass, buttonRC,
- XmNspacing, 2,
- NULL);
- XtAddCallback(tb,XmNactivateCallback,buttonCB,i);
- }
-
- }
-
- void
- toggleCB(w,i)
- Widget w;
- int i;
- {
- switch(i) {
- case 0 :
- drawAxis = !drawAxis;
- drawScene();
- break;
- case 1 :
- degenMode = !degenMode;
- drawScene();
- break;
- case 2 :
- lightWeight = !lightWeight;
- drawScene();
- break;
- case 3 :
- fog = !fog;
- if (fog) {
- defFog();
- }
- drawScene();
- break;
- case 4 :
- dontBlend = !dontBlend;
- drawScene();
- break;
- case 5 :
- moveSlice = !moveSlice;
- drawScene();
- break;
- case 6 :
- displayClipPlanes = !displayClipPlanes;
- drawScene();
- break;
- }
- }
-
- void
- viewCB(w,which)
- Widget w;
- int which;
- {
- specificView(which+1);
- }
-
- void
- buttonCB(w,which)
- Widget w;
- int which;
- {
- void infoDialog();
- switch(which) {
- case 0 :
- resetView();
- drawScene();
- break;
- case 1 :
- infoDialog(w);
- break;
- case 2 :
- doExit();
- break;
- }
- }
-
- void
- clipOnOffCB(w,which)
- Widget w;
- int which;
- {
- int i;
-
- clip[which].onOff = !clip[which].onOff;
-
- if (clip[which].onOff==1) {
- doClipping = 1;
- activeClipPlane = which;
- }
- else {
- doClipping = 0;
- for (i=0;i<MAXCLIP;i++) {
- if (clip[i].onOff==1) {
- doClipping = 1;
- break;
- }
- }
- }
- refresh = 1;
- drawScene();
- }
-
- void
- clipMoveCB(w,dir)
- Widget w;
- int dir;
- {
- }
-
- static char infoText[] = "\
- Volume Rendering using 2D and 3D textures\n\n\
- Author : Yusuf Attarwala (SGI-Applications)\n\n\
- \
- To run the program in 3d texture mode, type texvol -tex 3\n\
- The default mode is 2d texture mode.\n\
- \n\
- In the 2D texture mode, the program maintains three orthogonal sets of planes\n\
- on which 2d textures are mapped. Depending upon the direction of view,\n\
- one set is selected and the textures from these planes are composited using \n\
- blendfunction.\n\
- \
- The data is 128 x 128 x 64 slices of 8 bit values.\n\
- \
- Left Mouse : X and Y rotation\n\
- Middle Mouse : Zoom \n\
- Left & Middle Mouse : Z rotation (order of click important)\n\
- Middle & Left Mouse : Panning (order of click important)\n\
- Up & Down Arrow Keys : Move active clipping plane\n\
- \
- In Low Res Mode, use Left and Right arrows to control\n\
- resolution.\n\
- \
- In Depth Cue Mode, use Left and Right arrows to control\n\
- fog density.\n\
- ";
-
-
- void
- infoDialog(w)
- Widget w;
- {
- Widget dialog;
- XmString text;
- char line[125];
-
- text = XmStringCreateLtoR(infoText,XmSTRING_DEFAULT_CHARSET);
- XtSetArg(args[0],XmNmessageString,text);
- XtSetArg(args[1],XmNautoUnmanage,False);
- XtSetArg(args[2],XmNsymbolPixmap,NULL);
- XtSetArg(args[3],XmNtitle,"Texture Volume HELP");
- dialog = XmCreateInformationDialog(w,"helpDialog",args,4);
-
- XmStringFree(text);
-
- XtUnmanageChild(XmMessageBoxGetChild(dialog,XmDIALOG_CANCEL_BUTTON));
- XtUnmanageChild(XmMessageBoxGetChild(dialog,XmDIALOG_HELP_BUTTON));
- XtAddCallback(dialog,XmNokCallback,XtDestroyWidget,NULL);
-
- XtManageChild(dialog);
- XtPopup(XtParent(dialog),XtGrabNone);
- }
-